package com.qf.service.impl;

import com.qf.dao.StuDao;
import com.qf.dao.impl.StuDaoImpl;
import com.qf.domain.Stu;
import com.qf.service.StuService;

import java.util.List;

public class StuServiceImp implements StuService {
    private StuDao stuDao=new StuDaoImpl();
    @Override
    public Stu login(String stuname, String pwd) {
        Stu stu=stuDao.selectByStuName(stuname);
        if (stu == null) {
            throw new RuntimeException("用户名不存在");
        }
        if(!stu.getPwd().equalsIgnoreCase(pwd)){
            throw new RuntimeException("密码错误");
        }
        return stu;
    }

    @Override
    public List<Stu> findAll() {
        return stuDao.selectAll();
    }

    @Override
    public void addStu(Stu stu) {
        stuDao.insertStu(stu);
    }

    @Override
    public void modiy(Stu stu) {
        stuDao.update(stu);
    }

    @Override
    public Stu findById(int id) {
        return stuDao.selectById(id);
    }

    @Override
    public void remove(int id) {
        stuDao.delete(id);
    }
}
